#include "mainwindow.h"

#include <NavigateBar.h>
#include <QVBoxLayout>
#include <QMouseEvent>
#include "customframe.h"

MainWindow::MainWindow(QWidget *parent)
    : QWidget(parent)
{
    this->resize(1200,800);
    this->setWindowFlags(Qt::FramelessWindowHint); //设置为无边框窗口
    // setMouseTracking(true); //开启鼠标追踪
    this->setAttribute(Qt::WA_StyledBackground); //样式表设置样式生效
    this->setAttribute(Qt::WA_TranslucentBackground); //透明背景
    this->setStyleSheet("MainWindow{border:5px solid #0f1423;background-color:#262937;border-radius:35px;}"); //窗口样式

    // 左侧导航栏容器
    CustomFrame * frameNav = new CustomFrame(this);
    frameNav->resize(75,730);
    frameNav->move(25,35);
    frameNav->setEventAccept();
    // frameNav->setStyleSheet("QFrame{background-color:white}");
    // // 中部子窗口容器
    CustomFrame * frameMain = new CustomFrame(this);
    frameMain->move(120,35);
    frameMain->resize(685,730);

    frameMain->setStyleSheet("QFrame{background-color:#171b21;border-radius:25px;}");
    // // 右侧子窗口容器
    CustomFrame * frameSideBar = new CustomFrame(this);
    frameSideBar->move(825,35);
    frameSideBar->resize(350,730);
    frameSideBar->setStyleSheet("QFrame{background-color:#171b21;}");

    NavigateBar * nav = new NavigateBar();
    nav->setParent(frameNav);

}

void MainWindow::paintEvent(QPaintEvent *event)
{
    // 重绘窗口
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget,&opt,&p,this);
    // QWidget::paintEvent(event);
}

MainWindow::~MainWindow()
{
}

void MainWindow::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        isDragging = true;
        dragPosition = event->globalPos() - this->frameGeometry().topLeft(); // 获取鼠标相对于窗口的位置
    }
}

void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
    if (isDragging) {
        // 移动窗口到鼠标当前位置
        this->move(event->globalPos() - dragPosition);
    }
}

void MainWindow::mouseReleaseEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        isDragging = false; // 停止拖动
    }
}

// void MainWindow::enterEvent(QEvent *event)
// {
//     qDebug() << "enterEvent" ;
// }

// void MainWindow::leaveEvent(QEvent *event)
// {
//     qDebug() << "leaveEvent" ;
// }

